Skip to main content

Python Virtual Environment Setup

Introduction

In this tutorial, you will learn how to set up a Python virtual environment and configure Jupyter Notebook to work within this environment. This is useful for managing project dependencies and ensuring that different projects have their own isolated environments.

Setting Up a Python Virtual Environment

Step 1: Install Python

Ensure you have Python installed on your system. You can download the latest version from the official Python website.

Verify the installation by running:

python --version

Step 2: Install virtualenv

To create virtual environments, you need to install virtualenv. You can install it using pip:

pip install virtualenv

Step 3: Create a Virtual Environment

Navigate to your project directory and create a virtual environment:


cd your_project_directory
virtualenv venv

This creates a directory named venv that contains the virtual environment.

Step 4: Activate the Virtual Environment

Activate the virtual environment using the following command:

Windows:

venv\Scripts\activate

macOS/Linux:

source venv/bin/activate

Once activated, you will see the virtual environment's name in the terminal prompt.